package com.bestsoft.web.controller.flow;

import com.bestsoft.common.annotation.Log;
import com.bestsoft.common.core.controller.BaseController;
import com.bestsoft.common.core.domain.AjaxResult;
import com.bestsoft.common.core.page.TableDataInfo;
import com.bestsoft.common.enums.BusinessType;
import com.bestsoft.common.utils.poi.ExcelUtil;
import com.bestsoft.flow.domain.FlowOwnerDoc;
import com.bestsoft.flow.service.IFlowOwnerDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 货主资料Controller
 * 
 * @author 崔健
 * @date 2023-07-11
 */
@RestController
@RequestMapping("/flow/ownerdoc")
public class FlowOwnerDocController extends BaseController
{
    @Autowired
    private IFlowOwnerDocService flowOwnerDocService;

    /**
     * 查询货主资料列表
     */
    @PreAuthorize("@ss.hasPermi('flow:ownerdoc:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowOwnerDoc flowOwnerDoc)
    {
        startPage();
        List<FlowOwnerDoc> list = flowOwnerDocService.selectFlowOwnerDocList(flowOwnerDoc);
        return getDataTable(list);
    }

    /**
     * 导出货主资料列表
     */
    @PreAuthorize("@ss.hasPermi('flow:ownerdoc:export')")
    @Log(title = "货主资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowOwnerDoc flowOwnerDoc)
    {
        List<FlowOwnerDoc> list = flowOwnerDocService.selectFlowOwnerDocList(flowOwnerDoc);
        ExcelUtil<FlowOwnerDoc> util = new ExcelUtil<FlowOwnerDoc>(FlowOwnerDoc.class);
        util.exportExcel(response, list, "货主资料数据");
    }

    /**
     * 获取货主资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:ownerdoc:query')")
    @GetMapping(value = "/{ownerid}")
    public AjaxResult getInfo(@PathVariable("ownerid") Long ownerid)
    {
        return success(flowOwnerDocService.selectFlowOwnerDocByOwnerid(ownerid));
    }

    /**
     * 新增货主资料
     */
    @PreAuthorize("@ss.hasPermi('flow:ownerdoc:add')")
    @Log(title = "货主资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowOwnerDoc flowOwnerDoc)
    {
        return toAjax(flowOwnerDocService.insertFlowOwnerDoc(flowOwnerDoc));
    }

    /**
     * 修改货主资料
     */
    @PreAuthorize("@ss.hasPermi('flow:ownerdoc:edit')")
    @Log(title = "货主资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowOwnerDoc flowOwnerDoc)
    {
        return toAjax(flowOwnerDocService.updateFlowOwnerDoc(flowOwnerDoc));
    }

    /**
     * 删除货主资料
     */
    @PreAuthorize("@ss.hasPermi('flow:ownerdoc:remove')")
    @Log(title = "货主资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ownerids}")
    public AjaxResult remove(@PathVariable Long[] ownerids)
    {
        return toAjax(flowOwnerDocService.deleteFlowOwnerDocByOwnerids(ownerids));
    }
}
